home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
cdev
/
clrnxtwd.sit
/
Test code.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-11-03
|
3KB
|
162 lines
/*
* NeXT WDEF testing code
*/
#include <Global.h>
typedef struct {
int jump;
long add;
} defRec, *defPtr, **defHdl;
defHdl theDef;
EventRecord event;
Boolean hasQuit = false;
main()
{
Boolean gotEvent;
WindowPtr window;
int i;
Handle menuBar;
Rect wRect;
pascal long nextWDEF(/* variation, window, message, parameter */);
InitGraf(&thePort);
InitCursor();
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(nil);
MoreMasters();
MoreMasters();
FlushEvents(everyEvent, 0); /* flush toilet */
GetNextEvent(everyEvent, &event);
GetNextEvent(everyEvent, &event);
theDef = (defHdl)GetResource('WDEF', 10);
(**theDef).jump = 0x4ef9;
(**theDef).add = (long)nextWDEF;
menuBar = GetNewMBar(128);
SetMenuBar(menuBar);
DisposHandle(menuBar);
AddResMenu(GetMHandle(128), 'DRVR');
DrawMenuBar();
SetRect(&wRect, 20, 60, 420, 360);
window = NewWindow((WindowPeek)nil, &wRect, "\pThis is obviously a very nice window.", true, 168, (WindowPeek)-1l, true, 0);
OffsetRect(&wRect, 40, 40);
window = NewCWindow(nil, &wRect, "\pThe 2nd window!", true, 168, -1l, true, 0);
do {
SystemTask();
gotEvent = GetNextEvent(everyEvent, &event);
if (gotEvent) {
switch(event.what) {
case mouseDown:
DoMouseDown();
break;
case updateEvt:
DoUpdate((WindowPtr) event.message);
break;
}
}
} while(!hasQuit);
}
DoMouseDown()
{
short part;
WindowPtr window;
long growResult;
Rect growRect;
part = FindWindow(event.where, &window);
switch (part) {
case inMenuBar:
doMenu(MenuSelect(event.where));
break;
case inDrag:
DragWindow(window, event.where, &screenBits.bounds);
break;
case inContent:
if ( window != FrontWindow() )
SelectWindow(window);
case inGoAway:
SetPort(window);
if ( TrackGoAway(window, event.where) )
hasQuit = true;
break;
case inGrow:
SetPort(window);
SetRect(&growRect, 80, 60, 600, 500);
growResult = GrowWindow(window, event.where, &growRect);
if (growResult != 0)
SizeWindow(window, LoWord(growResult), HiWord(growResult), true);
break;
case inZoomIn:
case inZoomOut:
SetPort(window);
if ( TrackBox(window, event.where, part) ) {
EraseRect(&thePort->portRect);
ZoomWindow(window, part, window == FrontWindow());
InvalRect(&thePort->portRect);
}
break;
}
}
doMenu(mChoice)
long mChoice;
{
int menuID, menuItem;
WindowPtr window;
Rect wRect;
menuID = HiWord(mChoice);
menuItem = LoWord(mChoice);
window = FrontWindow();
if (menuID == 129)
switch(menuItem) {
case 1: case 2: case 3: case 4: case 5:
DisposeWindow(window);
SetRect(&wRect, 60, 60, 360, 300);
window = NewWindow(nil, &wRect, "\pChanged.", true, 160+menuItem-1, (WindowPtr)-1l, true, 0l);
break;
case 6:
DisposeWindow(window);
SetRect(&wRect, 70, 70, 360, 300);
window = NewWindow(nil, &wRect, "\pBack again.", true, 168, (WindowPtr)-1l, true, 0l);
break;
case 8:
hasQuit = true;
break;
}
HiliteMenu(0);
}
DoUpdate(window)
WindowPtr window;
{
Rect box;
SetPort(window);
BeginUpdate(window);
if ( ! EmptyRgn(window->clipRgn) ) {
PenNormal();
EraseRgn(window->clipRgn);
SetRect(&box, 10, 10, 200, 200);
FillOval(&box, <Gray);
OffsetRect(&box, 10, -10);
FillOval(&box, &gray);
DrawGrowIcon(window);
}
EndUpdate(window);
}